package com.windupurnomo.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import android.database.sqlite.SQLiteDatabase;

import com.windupurnomo.R;
import com.windupurnomo.data.ActivityManagerData;
import com.windupurnomo.entity.Condition;
import com.windupurnomo.entity.Player;
import com.windupurnomo.entity.Resource;
import com.windupurnomo.entity.ShareInfo;
import com.windupurnomo.entity.TaskDay;

public class Function {
	public static final String timeFormat(int time){
		String t = "";
		if(time/10==0) t = "0"+time+":00";
		else t = time+":00";
		return t;
	}
	
	public static final Player defaultResConPlayer(Player p){
		Resource r = new Resource();
		Condition c = new Condition();
		r.setFood(Util.ResourceNumber.FOOD);
		r.setWater(Util.ResourceNumber.WATER);
		r.setPaper(Util.ResourceNumber.PAPER);
		c.setPower(Util.ConditionNumber.POWER);
		c.setSocial(Util.ConditionNumber.SOCIAL);
		c.setFinance(Util.ConditionNumber.FINANCE);
		c.setEiq(Util.ConditionNumber.EIQ);
		p.setResource(r);
		p.setCondition(c);
		return p;
	}
	
	public static final int score(ShareInfo shareInfo){
		Player p = shareInfo.getPlayer();
		int task = shareInfo.getNumScs()*20;
		int social = p.getCondition().getSocial()*30;
		int eiq = p.getCondition().getEiq()*50;
		return task + social + eiq;
	}
	
	public static final int getTaskPictName(int taskId){
		switch(taskId){
			case 0: return R.drawable.task1;
			case 1: return R.drawable.task2;
		}
		return R.drawable.task3;
	}
	
	public static final boolean isTaskSuccess(int current, int start, int finish, int nextTime, int weather, int rainStart, int rainFinish, int taskPlace){
		boolean scs = true;
		if(weather==Util.DayWeather.RAIN){
			if(taskPlace==Util.TaskPlace.OUTDOOR){
				if((current>=rainStart && current<=rainFinish)||nextTime<=rainFinish){
					scs = false;
				}
			}else scs = true;
		}else scs = true;
		
		if(current>=start && current<=finish && nextTime<=finish && scs) scs = true;
		else scs = false;
		
		return scs;
	}
	
	public static final List<TaskDay> randomTaskDay (List<TaskDay> ltd){
		int n = ltd.size();
		Random r = new Random();
		for(int i=0; i<n; i++){
			int x = r.nextInt(n);
			TaskDay td = ltd.get(x);
			ltd.remove(x);
			ltd.add(td);
		}
		return ltd;
	}
	
	public static final List<Integer> getGameDay(){
		List<Integer> listDay = new ArrayList<Integer>();
		Random r = new Random();
		int game = r.nextInt(5);
		
		
		return listDay;
	}
}
